﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace Bakındur.Theming
{
    public abstract class Theme
    {
        public virtual string Name { get { return "Temel"; } }
        public virtual string CssStyle { get { return "<style></style>"; } }
        public virtual Color BackgroundColor { get { return SystemColors.Control; } }
        public virtual Image BackgroundImage { get { return null; } }
        public virtual ImageLayout BackgroundImageLayout { get { return ImageLayout.None; } }
        public virtual Image SecondBackgroundImage { get { return null; } }
        public virtual ImageLayout SecondBackgroundImageLayout { get { return ImageLayout.None; } }
        public virtual Color TransparencyKey { get { return new Bitmap(BackgroundImage).GetPixel(0, 0); } }

        public override string ToString()
        {
            return Name;
        }
    }

    public interface IThemeAble
    {
        //void SetTheme();
        void ApplyTheme(Theme theme);
        Theme DefaultTheme { get; }
    }

    public class BlueTheme : Theme
    {
        public override string Name
        {
            get { return "Mavi"; }
        }

        public override Color BackgroundColor
        {
            get
            {
                return Color.Blue;
            }
        }

        public override string CssStyle
        {
            get
            {
                return @"
<style>
body {overflow-x: hidden; font-family:arial,helvetica,sans-serif; font-size:13px; vertical-align:middle;background-color:#CEF6F5;color:darkblue; padding:0px;margin:0px;}
div.resultset { color:black; font-weight:bold; margin-bottom:6px;}
.dict_result {  vertical-align:middle; padding:6px; color:#000; font-weight:normal;  }
.lang { background-color:#58ACFA; border-top:1px solid purple;border-bottom:1px solid blue; padding: 1px; }
</style>";
            }
        }

        public override Image BackgroundImage
        {
            get
            {
                return Bakındur.Properties.Resources.blue_bar;
            }
        }
    }

    public class GreenTheme : Theme
    {
        public override string Name
        {
            get { return "Yeşil"; }
        }

        public override Color BackgroundColor
        {
            get
            {
                return Color.Green;
            }
        }

        public override string CssStyle
        {
            get
            {
                return @"
<style>
body {
font-family:arial,helvetica,sans-serif;
overflow-x: hidden; 
font-size:13px; 
vertical-align:middle;background-color:lightgreen;
color:darkgreen; 
padding:0px;margin:0px;
}
div.resultset { color:#F4FA58; font-weight:normal; margin-bottom:6px;}
.dict_result {  vertical-align:middle; padding:6px; color:#000; font-weight:normal;  }
.lang { background-color:darkgreen; border-top:1px solid Khaki;border-bottom:1px solid green; padding: 1px; }
</style>";
            }
        }

        public override Image BackgroundImage
        {
            get
            {
                return Bakındur.Properties.Resources.green_bar;
            }
        }
    }

    public class OrangeTheme : Theme
    {
        public override string Name
        {
            get { return "Turuncu"; }
        }

        public override Color BackgroundColor
        {
            get
            {
                return Color.Orange;
            }
        }

        public override string CssStyle
        {
            get
            {
                return @"
<style>
body {
overflow-x: hidden; 
font-family:arial,helvetica,sans-serif; font-size:13px; vertical-align:middle;background-color:#FFD97F;color:#ED3102; padding:0px;margin:0px;}
div.resultset { color:black; font-weight:bold; margin-bottom:6px;}
.dict_result {  vertical-align:middle; padding:6px; color:#000; font-weight:normal;  }
.lang { background-color:#FF8000; border-top:1px solid black;border-bottom:1px solid #F4A091; padding: 1px; }
</style>";
            }
        }

        public override Image BackgroundImage
        {
            get
            {
                return Bakındur.Properties.Resources.orange_bar;
            }
        }
    }

    public class SteelTheme : Theme
    {
        public override string Name
        {
            get { return "Çelik"; }
        }

        public override Color BackgroundColor
        {
            get
            {
                return Color.SteelBlue;
            }
        }

        public override string CssStyle
        {
            get
            {
                return @"
<style>
body 
overflow-x: hidden; 
font-family:arial,helvetica,sans-serif; font-size:13px; vertical-align:middle;background-color:#F2F2F2;color:black; padding:0px;margin:0px;}
div.resultset { color:black; font-weight:bold; margin-bottom:6px;}
.dict_result {  vertical-align:middle; padding:6px; color:#000; font-weight:normal;  }
.lang { background-color:lightgray; border-top:1px solid black;border-bottom:1px solid lightgray; padding: 1px; }
</style>";
            }
        }

        public override Image BackgroundImage
        {
            get
            {
                return Bakındur.Properties.Resources.steel_bar;
            }
        }
    }

    public class DarkTheme : Theme
    {
        public override string Name
        {
            get { return "Kara"; }
        }

        public override Color BackgroundColor
        {
            get
            {
                return Color.Blue;
            }
        }

        public override string CssStyle
        {
            get
            {
                return @"
<style>
body {
overflow-x: hidden; 
font-family:arial,helvetica,sans-serif; 
font-size:13px; 
vertical-align:middle;
background-color:#000;
color:white; 
padding:0px;margin:0px;
}
div.resultset { color:#000; font-weight:bold;margin-bottom:6px; }
.dict_result {  vertical-align:middle; padding:6px; color:#fff; font-weight:normal;  }
.lang { background-color:#E6E6E6; border-bottom:1px solid darkgray; padding: 1px; }
</style>";
            }
        }

        public override Image BackgroundImage
        {
            get
            {
                return Bakındur.Properties.Resources.dark_bar;
            }
        }
    }

    public class ThemeCollection : Dictionary<string, Type>
    {
        private static ThemeCollection _current;
        public static ThemeCollection Current
        {
            get
            {
                if (_current == null)
                    _current = new ThemeCollection();
                return _current;
            }
        }

        private ThemeCollection()
        {
            Add("Mavi", typeof(BlueTheme));
            Add("Yeşil", typeof(GreenTheme));
            Add("Portakal", typeof(OrangeTheme));
            Add("Çelik", typeof(SteelTheme));
            Add("Karanlık", typeof(DarkTheme));
        }

        public Theme GetTheme(string themeName)
        {
            try
            {
                Type type = this[themeName];
                if (type != null)
                    return Activator.CreateInstance(type) as Theme;
            }
            catch { }

            MessageBox.Show("Tema oluşturulamadı, varsayılan tema yükleniyor", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return new DarkTheme();
        }
    }
}
